package chinatelecom.feilong.license.manager;

import com.ideal.license.core.exception.CheckParamException;
import com.ideal.license.core.model.JiCengLicenseModel;
import com.ideal.license.core.model.LicenseModel;
import com.ideal.license.verifier.manager.VerifyModel;
import org.apache.commons.lang3.StringUtils;

public class CheckModelParam {

    public static void checkParam(LicenseModel model) throws CheckParamException {

        if (StringUtils.isBlank(model.getEdition())) {
            throw new CheckParamException("edition is null");
        }

        if (model instanceof JiCengLicenseModel) {
            JiCengLicenseModel mm = (JiCengLicenseModel)model;
            checkJiCheng(mm);
        }
    }

    private static void checkJiCheng(JiCengLicenseModel model) throws CheckParamException {
        if (null == model.getMacheinesNums() || model.getMacheinesNums() <= 0){
            throw new CheckParamException("macheinesNum is null");
        }
    }

    /**
     * 校验 veriferMdoel.
     * @param model
     */
    public static void checkVerifierModel(VerifyModel model) {
        if (StringUtils.isBlank(model.getEdition())) {
            throw new CheckParamException("edition is null");
        }
    }

}
